package com.os.opencv.java.chapter3;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;

import java.util.ArrayList;
import java.util.List;

public class SplitMerge {

    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        //将图像读取并在屏幕显示
        Mat src = Imgcodecs.imread("/Users/matt/MATT-MAC/matt_workspace/OS-OpenCV_workspace/eyeTest.jpeg");
        HighGui.imshow("src", src);
        HighGui.waitKey(0);

        //拆分图像通道
        List<Mat> dst = new ArrayList<>();
        Core.split(src, dst);

        for(Mat mat : dst){
            HighGui.imshow("dst", mat);
            HighGui.waitKey(0);
        }

        //合并图像通道
        Mat src2 = new Mat();
        Core.merge(dst, src2);

        //在屏幕上显示拆分后再合并的图像
        HighGui.imshow("split and merge", src2);
        HighGui.waitKey(0);
        System.exit(0);


    }
}
